<template>
  <div class="app-container agents-manage">
    <!-- 搜索 -->
    <el-form :model="state.queryParams" ref="queryRef" :inline="true">
      <el-form-item label="代理商名称" prop="agentsname">
        <el-input v-model="state.queryParams.wxpz_wxname" placeholder="代理商名称" clearable
          @keyup.enter="handleQuery({ initPageIndex: true })" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery({ initPageIndex: true })">搜索</el-button>
        <!-- <el-button type="primary" icon="Plus" plain @click="agentsExamineRef.openDialog()">新增</el-button> -->
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table v-loading="state.tableLoading" :data="state.tableData" row-key="agentsid" style="flex:1;">
      <el-table-column prop="depositslipid" label="付款单流水号" min-width="170" show-overflow-tooltip></el-table-column>
      <el-table-column prop="depositsagentsid" label="关联代理商id" min-width="170" show-overflow-tooltip></el-table-column>
      <el-table-column prop="depositsaccountid" label="关联客户id" min-width="170" show-overflow-tooltip></el-table-column>
      <el-table-column prop="depositsname" label="关联产品" min-width="200" show-overflow-tooltip></el-table-column>

      <el-table-column prop="depositslipype" label="付款单类型" min-width="100"></el-table-column>
      <el-table-column prop="depositslipprice" label="付款金额" min-width="100"></el-table-column>
      <el-table-column prop="depositslippaystatus" label="支付状态" min-width="100"></el-table-column>
      <el-table-column prop="depositslipfkdate" label="付款时间" min-width="100"></el-table-column>

      <el-table-column prop="depositslipcreateuser" label="创建人" min-width="150"></el-table-column>
      <el-table-column prop="depositslipcreatedate" label="创建时间" min-width="170"></el-table-column>
      <el-table-column label="操作" :width="fitWidth" class-name="small-padding fixed-width" fixed="right">
        <template #default="scope">
          <div class="operation-box">
            <el-text class="operate-btn-item" type="primary"
              @click="depositslipExamineRef.openDialog(scope.row)">审核</el-text>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-box">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="paginaionConfig.query.pageindex" :page-sizes="paginaionConfig.sizeOptions"
        :page-size="paginaionConfig.query.rows" layout="total, sizes, prev, pager, next, jumper"
        :total="paginaionConfig.total">
      </el-pagination>
    </div>

    <DepositslipExamine width="70%" ref="depositslipExamineRef" @refresh="handleQuery" />
  </div>
</template>

<script setup name="DepositslipExamine">
import useDepositslipManageManageStore from '@store/modules/depositslipManage'
import DepositslipExamine from '../components/DepositslipExamine/index.vue'
import _ from 'lodash'
import usePagination from '@/hooks/usePagination'
import useFitColumn from '@/hooks/useFitColumn'

const { proxy } = getCurrentInstance()
const depositslipManageStore = useDepositslipManageManageStore()
const { paginaionConfig, handleSizeChange, handleCurrentChange } = usePagination(handleQuery)
const { fitWidth } = useFitColumn()

const state = reactive({
  tableLoading: false,
  tableData: [],
  queryParams: {
    depositslippaystatus: '已支付',
    depositslipshstatus: '待审核'
  },
})
const depositslipExamineRef = ref(null)

/** 查询菜单列表 */
const getList = async (query) => {
  state.tableLoading = true
  const { Total, Data } = await depositslipManageStore.list(query)
  paginaionConfig.total = Total
  state.tableData = Data

  state.tableLoading = false
}

function handleQuery(config) {
  if (config?.initPageIndex) paginaionConfig.query.pageindex = 1
  getList(Object.assign(_.cloneDeep(paginaionConfig.query), state.queryParams))
}

onMounted(() => {
  handleQuery({ initPageIndex: true })
})
</script>
